package com.mkz.jbpm.feign;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.mkz.core.common.util.ResponseResult;
import com.mkz.core.log.annotation.SysLog;
import com.mkz.jbpm.activiti.ActIdService;
import com.mkz.jbpm.feign.ActiIdentityClient;

import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@Api(value = "ActiIdentity", tags = "工作流身份认证模块")
public class IActiIdentityClient implements ActiIdentityClient {
    @Autowired
    private ActIdService actiIdService;

	//添加或修改用户组
	@Override
	@SysLog("从RBAC同步用户组信息到JBPM模块")
  	@PutMapping(("/saveGroup"))
	public ResponseResult<Boolean> saveGroup(@RequestParam String roleCode, @RequestParam String roleName, @RequestParam String urrJson) {
		if(StrUtil.isBlank(roleCode)) {
			log.error("字段 roleCode 不能为空...");
			return ResponseResult.failed("参数错误...");
		}
		if(StrUtil.isBlank(roleName)) {
			log.error("字段 roleName 不能为空...");
			return ResponseResult.failed("参数错误...");
		}
		boolean dealResult = actiIdService.synGroupInfo(roleCode, roleName, urrJson);
		if(!dealResult) {
			return ResponseResult.failed("数据处理失败...");
		}
		return ResponseResult.ok(true);
	}

	//添加或修改用户组
	@Override
	@SysLog("从RBAC同步用户信息到JBPM模块")
  	@PutMapping("/saveUser")
	public ResponseResult<Boolean> saveUser(@RequestParam String userId, @RequestParam String fullname) {
		if(StrUtil.isBlank(userId)) {
			log.error("userId 不能为空...");
			return ResponseResult.ok(false);
		}
		boolean dealResult = actiIdService.synUserInfo(userId, fullname);
		if(!dealResult) {
			return ResponseResult.failed("数据处理失败...");
		}
		return ResponseResult.ok(true);
	}
}
